package com.fg.fgmall.controller;

import com.fg.fgmall.common.R;
import com.fg.fgmall.entity.Product;
import com.fg.fgmall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/products/{id}")
    public R selectProductById(@PathVariable("id") Integer id) {
        try {
            Product product = productService.selectById(id);
            return R.ok(product);
        } catch (Exception e) {
            return R.error();
        }
    }
}
